package com.customers.controller;

import com.customers.entity.MainForm;
import com.customers.service.CustomerService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/deleteCustomer")
public class CustomerDelServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String deletedId = request.getParameter("deletedId");
        System.out.println("id:"+deletedId);
        int id = Integer.parseInt(deletedId);

        try {
            CustomerService customerService = (CustomerService) request.getServletContext().getAttribute("CustomerService");
            String sql = "customerDel";
            MainForm form = new MainForm();
            form.setId(id);
            customerService.deleteCustomer(form,sql);
//            CustomerServic.deleteCustomer(id);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
